package com.baiye.template.controller;

import com.baiye.template.common.R;
import com.baiye.template.pojo.OrderVo;
import com.baiye.template.pojo.PayNotifyInfo;
import com.baiye.template.service.PayService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author GUOZHIPENG
 * @version 1.0
 * @date 2021/9/17 11:49
 */
@RestController
@Api(value = "订单")
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private PayService payService;

    //返回到前端
    @RequestMapping("/return")
    public R PayReturn(){
        return new R().ok();
    }

    //结果通知
    @RequestMapping(value = "/notify",method = RequestMethod.POST)
    public void PayNotify(PayNotifyInfo payNotifyInfo){
        if(payNotifyInfo.getTrade_status().equals("TRADE_SUCCESS")){
            payService.finishOrder(payNotifyInfo.getOut_trade_no());
        }
    }

    @RequestMapping(value="/pay",method = RequestMethod.POST)
    public R pay(@RequestBody OrderVo orderVo){
        String result = payService.aliPay(orderVo);
        return new R().ok(result);
    }
}
